var pGrid, pGridData, opt, picking_id, udata,picking_data;
$(function() {
    //ldz tab 从表切换事件
    $('#myTabs a').click(function (e) {
	  e.preventDefault()
	  $(this).tab('show')
	});
		
	// 明细列表设置
   	pGrid = $("#p-div").ligerGrid({
        columns:[
			{display:'id',name:'product_id',width:'1%',hide:true,
				render: function(rowdata, rowindex, value) {
					if(rowdata.id){
						return rowdata.id;
					}else{
						var currDate = new Date().format("yyyyMMddhhmmss");
						var uuid = Math.uuidFast();
						return currDate+"-"+uuid;
					}
	            }
			},	
			{display:'产品',name:'product_name',width:'10%'
//				editor:{type:'popup',onButtonClick:selectProduct}//ldz
			},
			{display:'内部货号',name:'product_code',width:'10%',textField:'product_code',valueField:'product_code'}, 
            {display:'规格属性',name:'product_att',width:'28%'},
            {display:'数量',name:'product_uom_qty',width:'10%',align:'right',
            	editor:{type:'string'},
            	render:function(item){
            		return item.product_uom_qty ? parseFloat(item.product_uom_qty).toFixed(2) : '';
            	}
            },
            {display:'单位',name:'product_uom',width:'10%',
            	render:function(item){
            		return paramRender(item,'uom',item.product_uom);
        		}
            },
            {display:'目的库位',name:'location',width:'10%'},
            {display:'状态',name:'state',width:'10%'}
        ], 
        pageSize:20, 
//        width:'100%',//ldz
        height:'99%', 
        rownumbers:true,
        fixedCellHeight:false, 
//        enabledEdit:true,//ldz 
        onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
        param_partner:'partner_list',
        //ldz
        alternatingRow: true,
        isScroll: false,
        usePager:true,
        editorTopDiff:4,
        editorLeftDiff:2
	});
	//解析URL传递的参数
	var query = getQueryString(window.location.toString());
	opt = query.o;

	if (opt) {
		picking_id = query.picking_id;
		if (opt === 'm') {
			ajaxSubmitGet("/stock/searchStock/" + picking_id, function(data) {
				//绑定数据
				bindVal(data);
			});
		}
	} else {
		$("#createDateS").val(new Date().format("yyyy-MM-dd hh:mm:ss"));
	}

	udata = getData('user', {
		orgid : $("#deptCodeS").val()
	}, false);

	$("#pageloading").hide();
});
function bindVal(data) {
	picking_data = data['data']; 
	//绑定主表数据 
	 
	$('#codeS').html(picking_data.code);
	$('#origin').html(picking_data.origin);
	$('#partnerInS').html(paramRender(null, 'partner_list', picking_data.partner_id));
	$('#partnerS').html(picking_data.partner_id);
	$('#pickTypeInS').html(paramRender(null, 'stock_picktype_list', picking_data.picking_type_id));
	$('#pickTypeS').html(picking_data.picking_type_id);
	$('#predDateS').html(picking_data.min_date); 
	$('#noteS').html(picking_data.note);
	$('#deptS').html(paramRender(null, 'org_list', picking_data.dept_id));
	$('#deptCodeS').html(picking_data.dept_id);
	$('#createUserS').html(paramRender(null, 'user', picking_data.create_uid)); 
	$('#createDateS').html(picking_data.create_date);

	//明细列表数据加载
	pGrid.setOptions({
		data : {
			Rows : picking_data['items']
		}
	}); //设置数据参数
	pGrid.loadData();//加载数据 
}
// 界面重新载入
function reloadPage() {
	window.location = './stock_picking_detail.html?o=m&picking_id='
			.concat(picking_id);
}
//界面的返回处理，实际是关闭标签处理。
function toBack() {
	//关闭修改界面
	parent.tabManager.removeTabItem("modify_stockp");
	//关闭修改界面1
	parent.tabManager.removeTabItem("modify_stockp1");
	//关闭明细界面
	parent.tabManager.removeTabItem("mx_stockp");
	//关闭新增界面
	parent.tabManager.removeTabItem("new_stockp");
	// new_search_stockS
	parent.tabManager.removeTabItem("new_search_stockS"+$('#codeS').val());
}
